﻿//添加
layui.use(function () {
    var $ = layui.$;
    var layer = layui.layer;
    var util = layui.util;
    var form = layui.form;
    // 对弹层中的表单进行初始化渲染
    form.render();
    // 表单提交事件
    form.on('submit(demo-login)', function (data) {
        WarehouseShow()
        var field = data.field;
        console.log(field)
        $.ajax({
            url: '/Qualityduring/QualityAdd',
            type: 'post',
            data: { data: JSON.stringify(field), token: localStorage.getItem("token") },
            success: function (res) {
                var s = JSON.parse(res)
                if (s.code == 1) {
                    layer.alert("添加成功");
                    setTimeout(function () {
                        location.href = '/Qualityduring/QualityduringShow'
                    }, 3000);
                }
                else {
                    layer.alert("添加失败");
                }
            }
        })
        return false; // 阻止默认 form 跳转
    });
    // 获取当前日期时间
    var now = new Date();
    var year = now.getFullYear()
    var month = ("0" + now.getMonth() + 1).slice(-2);
    var day = ("0" + now.getDate()).slice(-2);
    var hours = ("0" + now.getHours()).slice(-2);
    var minutes = ("0" + now.getMinutes()).slice(-2);
    var seconds = ("0" + now.getSeconds()).slice(-2);
    //批次号
    var Lotnumber = 'CP' + seconds + year
    var Lotnumbers = document.getElementById('finishedBatch');
    Lotnumbers.value = Lotnumber;
    //采购原料编号
    var Ingredient = 'SCX' + month + seconds + day
    var Ingredients = document.getElementById('productionlineNumber')
    Ingredients.value = Ingredient
    //质检编号
    var serialNumber = "ZJ" + hours + minutes + seconds;
    var inputElement = document.getElementById('QualityNumber');
    inputElement.value = serialNumber;
    console.log(inputElement.value)
})
$(function () {
    WarehouseShow()
})
function WarehouseShow() {
    layui.use('form', function () {
        var form = layui.form;
        var date = ["供应商一", "供应商二", "供应商三", "供应商四",]
        //console.log(date)
        var options = '<option value="">请选择型号</option>'; // 添加默认选项
        $.each(date, function (index, item) {
            options += '<option value="' + index + '">' + item + '</option>';
        });
        $(".dialog-select#SupplierID").html(options);
        form.render('select'); // 重新渲染下拉框
    });
}